<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Builder;
use App\Service\Classes\LayuiBuilder;

class BaseController extends Controller{
    
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * @param \Illuminate\Http\Request $request
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param Array $arrayQuery
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder
     */
    public function layuiQuery(
        Request $request,
        Builder $query,
        array $arrayQuery = []
    ) {
        return (new LayuiBuilder($request, $query, $arrayQuery))->query();
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param Array $arrayQuery
     * @return \Illuminate\Support\Collection
     */
    public function layuiDataset(
        Request $request,
        Builder $query,
        array $arrayQuery = []
    ) {
        return (new LayuiBuilder($request, $query, $arrayQuery))->paginate();
    }

    /**
     * @param \Illuminate\Http\Request $request
     * @param \Illuminate\Database\Eloquent\Builder $query
     * @param Array $arrayQuery
     * @param  callable|null  $callback
     * @return \Illuminate\Http\Response
     */
    public function layuiPaginate(
        Request $request,
        Builder $query,
        array $arrayQuery = [],
        $callback = null
    ) {
        return $this->status(
            FoundationResponse::HTTP_OK,
            (new LayuiBuilder($request, $query, $arrayQuery))->paginate($callback)->toArray()
        );
    }
}